#获取大写锁定状态 T大 F小
def get_capslock_state():
    import ctypes
    hllDll=ctypes.WinDLL("User32.dll")
    VK_CAPTIAL=0x14
    return (hllDll.GetKeyState(VK_CAPTIAL)&0xffff)!=0

import os
import pystray
import time
import _thread
from PIL import Image
from pystray import MenuItem
icon=pystray.Icon(None)

import socket
import json
import sys

def close():
    icon.stop()

def about():
    icon.notify("作者:Klezy(klezy@qq.com)","关于")

def pick():
    dirname=sys.argv[0].split("capslook.")[0]
    filepath=dirname+"/config.json"
    f=open(filepath,"r")
    config=json.load(f)
    sk=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sendmsg:bytes="data"
    sendmsg=b'cat'
    sk.sendto(sendmsg,(config["serverip"],config["serverport"]))



# menu 的 menuItem数量小于两个会报错
menu = (MenuItem('关于',lambda:about()),MenuItem('退出',lambda:close()),MenuItem('查询',lambda:pick()))
dir=os.path.split(os.path.realpath(__file__))[0]
imaged=Image.open(dir+"/D.png")
imagex=Image.open(dir+"/X.png")

icon=pystray.Icon('大小写显示',imagex,'小写',menu)

_thread.start_new_thread(icon.run,())

while(True):
    time.sleep(0.45)
    if(get_capslock_state()):
        icon.icon=imaged
    else:
        icon.icon=imagex



        
